<?php

/*
 * @copyright :     Ienter asia Technologies
 * @author :        HungLV
 * @version         v.1.0
 * @created         24/6/2014
 * @Description :   Controller Employee Bonus
 */
if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Mod_employeebonus extends MYAD_Controller {

    function __construct() {
        parent::__construct();
        $this->load->model('Mmod_employeebonus', 'be');
        $this->load->model('Mmod_employee', 'em');
    }

    function index($page = 0) { 
        $employeeID=$this->input->post('txtEmployeeId'); 
        $employee = $this->be->getEmployee($employeeID);  
        $data = $this->be->getAllData($employeeID, $page, $employee);
        $this->load->view('layout', $data);
    }

    /**
     * @author Hung        
     * @created:2014/06/23     
     * @function countAll 
     * @param: $employeeID (int), $ApplyDate(strtotime)          
     * @Output: int
     * @This function return number holiday on month  
     */ 
    
    function updateBonusInfo() {              
        if($this->input->post('txtApplyDateOld')!=""){
            $ApplyDate=$this->input->post('txtApplyDateOld');
        }  else {
            $ApplyDate=NULL;
        }
        $employeeID=$this->input->post('txtEmployeeId');
       
        $temp = array();
        // check exist
        if($ApplyDate!=NULL && $employeeID!=0 && !$this->be->checkExist($employeeID,$ApplyDate)){
            redirect('employee');
        }        
        if (isset($_POST['btnSubmit'])) {
            $validateFlag = $this->be->validate();
            if ($validateFlag) {
                /* validate success */
                $id = $this->input->post('txtEmployeeId');
                $temp = $this->be->updateEmployeeBonusInfo($id, $ApplyDate);
            }
        }
        $employee = $this->be->getEmployee($employeeID);
        $data = $this->be->getAddBonusInfo($employeeID, $ApplyDate, $employee);
       // var_dump($data); die;
        $this->load->view('layout', array_merge($data, $temp));
    }

}

?>